﻿using SMplusXTeam.SyncMoped.SyncGurke;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;

namespace SMplusXTeam.SyncMoped.SyncGurkeTest
{


    /// <summary>
    ///This is a test class for DirectoryComparisonTest and is intended
    ///to contain all DirectoryComparisonTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DirectoryComparisonTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for CompareDirectories
        ///</summary>
        [TestMethod()]
        public void CompareDirectoriesTest()
        {
            string sourceDirectory = @"c:\Windows\assembly";
            string targetDirectory = @"c:\Windows\assembly";
            ComparisonMethod comparisonMethod = ComparisonMethod.Md5;
            DirectoryComparisonResult actual = DirectoryComparison.CompareDirectories(sourceDirectory, targetDirectory, comparisonMethod);
            Assert.IsTrue(Enumerable.SequenceEqual(actual.EqualFiles.OrderBy(t => t), FileHelper.GetFiles(sourceDirectory).OrderBy(t => t)));
            Assert.AreEqual(actual.DeletedFiles.Count, 0);
            Assert.AreEqual(actual.UnequalFiles.Count, 0);
            Assert.AreEqual(actual.NewFiles.Count, 0);
        }
        /// <summary>
        ///A test for CompareDirectories
        ///</summary>
        [TestMethod()]
        public void CompareDirectoriesTest1()
        {
            string sourceDirectory = @"c:\Windows\System32";
            string targetDirectory = @"c:\Windows\System32";
            ComparisonMethod comparisonMethod = ComparisonMethod.Md5;
            DirectoryComparisonResult actual = DirectoryComparison.CompareDirectories(sourceDirectory, targetDirectory, comparisonMethod);
            Assert.IsTrue(actual.FailedFiles.LongCount() > 0);
            Assert.IsTrue(actual.EqualFiles.LongCount() > 0);
            Assert.IsTrue(actual.UnequalFiles.LongCount() == 0);
            Assert.AreEqual(actual.NewFiles.Count, 0);
        }

        /// <summary>
        ///A test for CompareDirectories
        ///</summary>
        [TestMethod()]
        public void CompareDirectoriesTest2()
        {
            string sourceDirectory = @"c:\Windows\System32";
            string targetDirectory = @"c:\Windows\System32";
            ComparisonMethod comparisonMethod = ComparisonMethod.Modified;
            DirectoryComparisonResult actual = DirectoryComparison.CompareDirectories(sourceDirectory, targetDirectory, comparisonMethod);
            Assert.IsTrue(actual.FailedFiles.LongCount() == 0);
            Assert.IsTrue(actual.EqualFiles.LongCount() > 0);
            Assert.IsTrue(actual.UnequalFiles.LongCount() == 0);
            Assert.AreEqual(actual.NewFiles.Count, 0);
        }
    }
}
